import requestMeeting, { request } from '@/plugins/axios'
import {
	ReservationLogRequestParam,
	FetchLogParam,
	FetchReservationLogData,
	MccMeetingLogRequestParam,
	FetchMccMeetingLogData,
	MccLogDetailListRequestParam,
	FetchMccLogDetailListData,
	FetchMccLogDetailData,
} from './interface'

/** 获取保存期限 */
export const fetchGetDeadLine = async () =>
	requestMeeting<number>({
		url: '/meeting_logs/system_logs/deadline',
		method: 'get',
	}).then((res) => (res.success ? res.data : undefined))

/** 设置保存期限 */
export const fetchSetDeadLine = async (deadline: number) =>
	requestMeeting({
		url: '/meeting_logs/system_logs/deadline',
		method: 'post',
		params: { deadline },
	})

/** 获取综合日志列表 */
export const fetchGetReservationLog = async (params: ReservationLogRequestParam) =>
	request<FetchLogParam<FetchReservationLogData>>({
		url: '/meeting_logs/system_logs',
		method: 'get',
		params: params,
	}).then((res) => (res.success ? { data: res.data ?? [], total: res.total ?? 0 } : undefined))

/** 获取综合日志详细 */
export const fetchGetReservationLogDetail = async (id: number) =>
	requestMeeting<string>({
		url: '/meeting_logs/detail/' + id,
		method: 'get',
	}).then((res) => (res.success ? res.data : undefined))

/** 获取会议管理日志列表 */
export const fetchGetMccMeetingLog = async (params: MccMeetingLogRequestParam) =>
	request<FetchLogParam<FetchMccMeetingLogData>>({
		url: '/mcc_logs/meetings',
		method: 'get',
		params: params,
	}).then((res) => (res.success ? { data: res.data ?? [], total: res.total ?? 0 } : undefined))

/** 获取会议管理日志详情列表 */
export const fetchGetMccLogDetailList = async (meeting_moid: string, params: MccLogDetailListRequestParam) =>
	request<FetchLogParam<FetchMccLogDetailListData>>({
		url: `/mcc_logs/meetings/${meeting_moid}/logs`,
		method: 'get',
		params: params,
	}).then((res) => (res.success ? { data: res.data ?? [], total: res.total ?? 0 } : undefined))

/** 获取会议管理日志详情 */
export const fetchGetMccMeetingLogDetail = async (meeting_moid: string, id: number) =>
	request<FetchMccLogDetailData>({
		url: `/mcc_logs/meetings/${meeting_moid}/logs/${id}`,
		method: 'get',
		params: { meeting_moid },
	}).then((res) => (res.success ? res : undefined))
